package run.siyuan.service;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import run.siyuan.mapper.CommissionBillingMapper;
import run.siyuan.model.CommissionBilling;
import run.siyuan.model.CommissionSettlement;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 佣金账单服务
 *
 * @author jinjingsu
 * @date 2021/03/19
 */
@Service
@Slf4j
public class CommissionBillingService extends ServiceImpl<CommissionBillingMapper, CommissionBilling> {

    /**
     * 更新明细
     *
     * @param commissionSettlements
     */
    public List<Long> updateCommissionBillings(List<CommissionSettlement> commissionSettlements) {
        long current = DateUtil.current();
        List<Long> commissionBillingIds = commissionSettlements.stream().map(CommissionSettlement::getCommissionBillingId).collect(Collectors.toList());
        this.update(
                Wrappers.lambdaUpdate(CommissionBilling.class)
                        .set(CommissionBilling::getEntryBalance, true)
                        .set(CommissionBilling::getEntryBalanceTime,current)
                        .in(CommissionBilling::getCommissionBillingId, commissionBillingIds)
        );
        return commissionBillingIds;
    }


}
